﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Libs.Content;

public partial class Controls_NewsCate : System.Web.UI.UserControl
{
    public int CateID
    {
        get;
        set;
    }

    public int RowNumber
    {
        get;
        set;
    }

    public int CharLenght
    {
        get;
        set;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;

        NewsWeb _NewsWeb = new NewsWeb();
        NewsCategories _Cate = new NewsCategories() { CateID = CateID };
        List<NewsWeb> list;

        list = _NewsWeb.GetList(_Cate.CateID, 0, RowNumber);
        for (int i = 0; i < list.Count; i++)
        {
            _NewsWeb = list[i];
            _NewsWeb.Title = NewsUtils.AddIcon(_NewsWeb);
            list[i] = _NewsWeb;
        }
        _Cate = _Cate.Get();

        hlCate.NavigateUrl = NewsUtils.CateLink(_Cate.CateID.ToString(), _Cate.Url, "0");
        hlCate.Text = _Cate.Name.ToUpper();

        _NewsWeb = list[0];
        if (_NewsWeb.SubLead.Length > CharLenght)
        {
            _NewsWeb.SubLead = _NewsWeb.SubLead.Substring(0, CharLenght) + "...";
        }
        list.RemoveAt(0);
        if (string.IsNullOrEmpty(_NewsWeb.ImageUrl)) _NewsWeb.ImageUrl = "no_image.jpg";
        ltrNews.Text = Resources.Html.NewsCate;
        ltrNews.Text = ltrNews.Text.Replace("$Link$", _NewsWeb.Url);
        ltrNews.Text = ltrNews.Text.Replace("$Title$", _NewsWeb.Title);
        ltrNews.Text = ltrNews.Text.Replace("$ImageUrl$", AppUtils.ImageUrl(_NewsWeb.ImageUrl, "310", "194"));
        ltrNews.Text = ltrNews.Text.Replace("$Time$", _NewsWeb.PublishedTime.ToString("dd/MM/yyyy"));
        ltrNews.Text = ltrNews.Text.Replace("$Lead$", _NewsWeb.SubLead);

        rptList.DataSource = list;
        rptList.DataBind();
    }
}